﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="../../favicon.ico" />
    <!--jquery库-->
    <script src="../../js/jquery.min.js"></script>
    <!--bootstrap库-->
    <link href="../../css/bootstrap.min.css" rel="stylesheet" />
    <script src="../../js/bootstrap/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
      <script src="../../js/bootstrap/html5shiv.min.js"></script>
      <script src="../../js/bootstrap/respond.min.js"></script>
    <![endif]-->
    <!--font-awesome字体库-->
    <link href="../../css/font-awesome.min.css" rel="stylesheet" />
    <!--流式布局库-->
    <script src="../../js/jquery.masonry/masonry.pkgd.min.js"></script>
    <!--图片延时加载库-->
    <script src="../../js/jquery.lazyload/jquery.lazyload.min.js"></script>
    <style>
        .template { border: 1px solid #b6ff00; }
    </style>
    <script>
        var base;
        var base1;
        var $grid;
        $(function () {
            base = $(".template");
            base1 = base.clone();
            base1.html(base1.html().replace("300x150", "300x300"));

            // init Masonry
            $grid = $('.content').masonry({
                columnWidth: '.template',
                itemSelector: '.template'
            });
            append();
        })
        function append() {
            var tempResults = [];
            for (var i = 0; i < 10; i++) {
                var temp;
                if (i % 2 == 0) {
                    temp = base.clone();
                } else {
                    temp = base1.clone();
                }
                temp.html(temp.html().replace("text=1", "text=" + (2 + i)));
                tempResults.push(temp.get(0));   //push dom objct
            }
            $tempResults = $(tempResults);
            $grid.append($tempResults).masonry('appended', $tempResults);
            //图片延迟加载库(这个是跟masonry库没有关系的，只是在一个地方看到可以配合使用才这么办的)
            $grid.find("img.nolazy").lazyload({
                effect: 'fadeIn',
                load: function () {
                    // Disable trigger on this image
                    $(this).removeClass("nolazy");
                    $grid.masonry();
                }
            });
        }
    </script>
</head>
<body>
    <div class="container">
        <div class="row content">
            <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 template">
                <div class="row">
                    <img src="../../image/picture-loading.gif" data-original="http://placehold.it/300x150?text=1" class="img-responsive nolazy" />
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <a href="javascript:void(0);" onclick="append();" class="btn btn-primary">添加More</a>
            </div>
        </div>
    </div>
</body>
</html>
